<style>

</style>

<template>
	<div id="home">
		<div class="zb_container">
			<div class="zb_content">
				<div>
					<div v-show="false">
						<input type="text" name="materialEntryId" id="materialEntryId" v-model="data.materialEntryId" />
						<input type="text" name="organId" id="organId" v-model="data.organId" />
						<input type="text" name="manageOrganId" id="manageOrganId" v-model="data.manageOrganId" />
						<input type="text" name="deptId" id="deptId" v-model="data.deptId" />
						<input type="text" name="positionId" id="positionId" v-model="data.positionId" />
						<input type="text" name="fullId" id="fullId" v-model="data.fullId" />
						<input type="text" name="stageIds" id="stageIds" v-model="data.stageIds" />
						<input type="text" name="projectId" id="projectId" v-model="data.projectId" />
						<input type="text" name="status" id="status" v-model="data.status" />
						<input type="text" name="personMemberId" id="personMemberId" v-model="data.personMemberId" />
						<input type="text" name="contractId" id="contractId" v-model="data.contractId" />
						<input type="text" name="supplierId" id="supplierId" v-model="data.supplierId" />
						<input type="text" name="bizOperatorId" id="bizOperatorId" v-model="data.bizOperatorId" />
						<input type="text" name="stageMainId" id="stageMainId" v-model="data.stageMainId" />
					</div>
					<div>
						<!--附件-->
						<div class="mb_10" v-if="fileData.length>0" id="divAttachment">
							<div class="text_title" onclick="Public.setPanelStatus('attachmentPanel','fileData')">
								<div>
									<i class="icon-accessory"></i>附件--合同材料进场表
									<div style="float: right;" class="arrow_icon arrow_icon_up">
										<i class="fa fa-angle-double-up" id="fileData"></i>
									</div>
									<!--</dienclosure_icon.pngv>-->

								</div>
							</div>
							<div id="attachmentPanel">
								<!-- @click="goFileData(list.id)" -->
								<div class="preview" v-for="list in fileData" @click="goFileData(list.id)">
									<a href="javascript:;">
										<img src="../../static/images/enclosure_icon.png" />
										<span v-html="list.fileName"></span>
										<div style="float: right;margin-right: .12rem;" class="arrow_icon_right">
											<i class="fa fa-angle-double-up" id="file_data_icon"></i>
										</div>
									</a>
								</div>

							</div>

						</div>

						<!--审批流程-->
						<div class="mb_10" v-show="aproveData.length>0">
							<div class="text_title">
								<div>
									<i class="icon-accessory"></i>审批流程
									<div style="float: right;">
										<i class="fa fa-angle-double-up" id="aAuditLink"></i>
									</div>
								</div>

							</div>
							<div id="auditPanel" class="box-content accessory approve">

							</div>

							<!--审批流程隐藏域-->
							<div style="display: none;">
								<input id="currentHandleId" type="text" name="id" />
								<input id="currentHandleGroupId" type="text" name="groupId" />
								<input id="currentHandleSequence" type="text" name="sequence" />
								<input id="currentHandleCooperationModelId" type="text" name="cooperationModelId" />
								<input id="currentHandleTaskExecuteModeId" type="text" name="taskExecuteModeId" />
								<input id="currentHandleAllowAdd" type="text" name="allowAdd" />
								<input id="currentHandleAllowSubtract" type="text" name="allowSubtract" />
								<input id="currentHandleAllowTransfer" type="text" name="allowTransfer" />
								<input id="currentHandleAllowAbort" type="text" name="allowAbort" />
								<input id="currentHandleHelpSection" type="text" name="helpSection" />
								<input id="currentHandleChiefId" type="text" name="chiefId" />
								<input id="currentApprovalRuleId" type="text" name="approvalRuleId" />
								<input id="currentHandleKindId" type="text" name="handleKindId" />
							</div>

						</div>

						<!--材料明细-->
						<div class="mb_10">
							<div class="text_title">
								<div>
									<i class="fa fa-laptop  fa-navbar"></i>材料明细
									<div class="toggleLinkPanelStyle">
										<i class="fa fa-angle-double-up"></i>
									</div>
								</div>
							</div>
							<div style="overflow: auto;" class="zb_scrollTable">
								<!-- table 版本-->
								<table class="table_grid" style="width: 700px;" border="0" cellspacing="0" cellpadding="0">
									<tr class="th">
										<td class="first_td">材料名称</td>
										<td style="min-width: 100px;max-width: 100px;" class="second_td">进场日期</td>
										<td style="min-width: 100px;max-width: 100px;">数量</td>
										<td style="min-width: 100px;max-width: 100px;">单位</td>
										<td style="min-width: 100px;max-width: 100px;">备注</td>
									</tr>
									<tr v-for="item in dataGrid">
										<td v-html="item.materialName" class="first_td"></td>
										<td v-html="item.entryDate" class="second_td"></td>
										<td v-html="item.quantity"></td>
										<td v-html="item.unitName"></td>
										<td v-html="item.remark"></td>
									</tr>
								</table>

							</div>

						</div>

						<!--基本信息-->
						<div class="mb_10">
							<div class="text_title" onclick="Public.setPanelStatus('msg_ul','msg_i')">
								<div>
									<i class="fa fa-laptop  fa-navbar"></i>基本信息
									<div class="arrow_icon arrow_icon_down msg_arrow" style="float: right;">
										<i class="fa fa-angle-double-up" id="msg_i"></i>
									</div>
								</div>
							</div>
							<ul id="msg_ul">
								<li class="clear">
									<span>所在单位</span>
									<span v-html="data.organName"></span>
								</li>
								<li class="clear">
									<span>单据号码</span>
									<span v-html="data.billCode"></span>
								</li>
								<li class="clear">
									<span>填表日期</span>
									<!-- .substring(0,10) -->
									<span v-html="data.fillinDate"></span>
								</li>
								<li class="clear">
									<span>所在部门</span>
									<span v-html="data.deptName"></span>
								</li>
								<li class="clear">
									<span>所在岗位</span>
									<span v-html="data.positionName"></span>
								</li>
								<li class="clear">
									<span>人员名称</span>
									<span v-html="data.personMemberName"></span>
								</li>
								<li class="clear">
									<span>标题</span>
									<span v-html="data.title"></span>
								</li>
								<li class="clear">
									<span>合同</span>
									<span v-html="data.contractName"></span>
								</li>
								<li class="clear">
									<span>中标通知书</span>
									<span v-html="data.bizId"></span>
								</li>

								<li class="clear">
									<span>项目名称</span>
									<span v-html="data.projectName"></span>
								</li>
								<li class="clear">
									<span>经办人</span>
									<span v-html="data.bizOperatorName"></span>
								</li>
								<li class="clear">
									<span>经办时间</span>
									<!-- .substring(0,10) -->
									<span v-html="data.bizOperatedDate"></span>
								</li>
								<li class="clear">
									<span>描述</span>
									<span v-html="data.description"></span>
								</li>

							</ul>

						</div>

					</div>
				</div>

				<!--底部按钮-->
				<div id="divBottomBtnPanel1" class="bottom_btn">
					<div class="footer_group">
						<ol id="btn_group_bottom" class="clear">
							<li id="save" class="f1" @click="save()">
								<i></i>
								<span>保存</span>
							</li>
							<li id="inform" class="f2" style="display:none;">
								<i></i>
								<span>知会</span>
							</li>
							<li id="assigned" class="f3" style="display:none;">
								<i></i>
								<span>交办</span>
							</li>

							<li id="submit" class="f4" @click="getadvance()">
								<i></i>
								<span class="submit_color">提交</span>
							</li>
							<li id="more" class="f5" style="display:none;">
								<i></i>
								<span>更多</span>
							</li>
						</ol>
					</div>
				</div>
				<div class="messageAlert1" style="display: none;">
					<p id="getback">
						<button type="button">回退</button>
					</p>
					<p id="theco">
						<button type="button">协审</button>
					</p>
					<p id="getaddsubsign">
						<button type="button">加减签</button>
					</p>
					<p id="suspension">
						<button type="button">暂缓</button>
					</p>
					<p id="termination">
						<button type="button">终止</button>
					</p>
				</div>
			</div>

		</div>
		<div style="display: none;">
			<form method="post" action="" id="handlerForm">
				<input id="currentHandleId" type="text" name="currentHandleId" />
				<input id="currentHandleGroupId" type="text" name="currentHandleGroupId" />
				<input id="currentHandleSequence" type="text" name="currentHandleSequence" />
				<input id="currentHandleCooperationModelId" type="text" name="currentHandleCooperationModelId" />
				<input id="currentHandleTaskExecuteModeId" type="text" name="taskExecuteModeId" />
				<input id="currentHandleAllowAdd" type="text" name="allowAdd" />
				<input id="currentHandleAllowSubtract" type="text" name="allowSubtract" />
				<input id="currentHandleAllowTransfer" type="text" name="allowTransfer" />
				<input id="currentHandleAllowAbort" type="text" name="allowAbort" />
				<input id="currentHandleHelpSection" type="text" name="helpSection" />
				<input id="currentHandleChiefId" type="text" name="chiefId" />
				<input id="currentApprovalRuleId" type="text" name="approvalRuleId" />
				<input id="currentHandleKindId" type="text" name="handleKindId" />
			</form>
		</div>
		<div v-show="false">
			<input type="text" id="leaveId" v-model="data.leaveId" />
			<input type="text" id="fullId" v-model="data.fullId" />
			<input type="text" id="organId" v-model="data.organId" />
			<input type="text" id="centerId" v-model="data.centerId" />
			<input type="text" id="centerName" v-model="data.centerName" />
			<input type="text" id="deptId" v-model="data.deptId" />
			<input type="text" id="positionId" v-model="data.positionId" />
			<input type="text" id="personMemberId" v-model="data.personMemberId" />
			<input type="text" id="positionName" v-model="data.positionName" />
			<input type="text" id="status" v-model="data.status" />
			<input type="text" id="deputyIdTemp" v-model="data.deputyIdTemp" />
			<input type="text" id="deputyFullIdTemp" v-model="data.deputyFullIdTemp" />
			<input type="text" id="deputyNameTemp" v-model="data.deputyNameTemp" />
		</div>
	</div>
</template>

<script>
export default {

	data() {
		return {
			// 基本信息数据
			data: {},
			// 附件
			fileData: [],
			// 审批列表
			aproveData: [],
			// 材料明细
			dataGrid: [],
			reqURL: {},
			PACTERA_URL: "http://test.pactera.com",
			XT_URL: "http://dev.brc.com.cn:9998",
			Bdata: '',
			tcAdjustmentId: '',
			isNewItems: '',
			kindId: '',
			viewParamService: {
				getHandlerdata: function(d) {
					var b = new Object();
					if (d == undefined) {
						return null
					} else {
						var f = d.split("&");
						for (var c = 0; c < f.length; c++) {
							var g = f[c].indexOf("=");
							if (g == -1) {
								continue
							}
							var a = f[c].substring(0, g);
							var e = f[c].substring(g + 1);
							b[a] = unescape(e)
						}
						return b
					}
				},
				getViewParam: function() {
					var c = new Object();
					var b = window.location.href;
					var e = b.split("?")[1];
					if (e == undefined) {
						return null
					} else {
						var g = e.split("&");
						for (var d = 0; d < g.length; d++) {
							var h = g[d].indexOf("=");
							if (h == -1) {
								continue
							}
							var a = g[d].substring(0, h);
							var f = g[d].substring(h + 1);
							c[a] = unescape(f)
						}
						return c
					}
				}

			},
			viewParam: {},

			JBcode: true // 交办标识
		}
	},
	methods: {

		getData() {
			this.reqURL = this.$route.query;
			var url = this.XT_URL + '/xt/' + this.reqURL.url.split('.')[0] + '.mbApp';
			delete this.reqURL.name;
			delete this.reqURL.a;
			delete this.reqURL.url;
			delete this.reqURL.statusId;
			delete this.reqURL.catalogId;
			delete this.reqURL.viewTaskKindId;
			this.reqURL.url = url;
			this.reqURL.procInstEndTime = '';
			var stageId = '',
				access_token = this.reqURL.access_token,
				bizCode = this.reqURL.bizCode,
				bizId = this.reqURL.bizId,
				procUnitId = this.reqURL.procUnitId,
				currentTaskId = this.reqURL.taskId,
				self = this;
			// 基本信息
			$.ajax({
				type: "POST",
				async: false,
				url: self.PACTERA_URL + "/BrcDataService/data/httppoxy",
				data: self.reqURL,
				success: function(msg) {
					debugger;
					var msg = JSON.parse(msg);
					self.data = msg.data;
					self.Bdata = msg.data;
					self.isNewItems = msg.data.isNewItems;
					self.kindId = msg.data.kindId;
					self.stageId = msg.data.stageId;
					self.tcAdjustmentId = msg.data.tcAdjustmentId;
				}
			});
			// 附件 
			$.ajax({
				type: 'post',
				async: false,
				url: self.PACTERA_URL + "/BrcDataService/data/httppoxy",
				data: {
					bizId: bizId,
					bizCode: "ResourceMaterialEntry",
					access_token: access_token,
					url: self.XT_URL + '/xt/attachmentAction!doQuery.mbApp'
				},
				success: function(data) {
					data = JSON.parse(data);
					self.fileData = data.data;
				}
			})
			// 审批列表
			$.ajax({
				type: 'post',
				async: false,
				url: self.PACTERA_URL + "/BrcDataService/data/httppoxy",
				data: {
					bizId: bizId,
					approvalProcUnitId: 'Approve', // 待定
					procUnitId: 'Approve',
					currentTaskId: currentTaskId, // 待定
					access_token: access_token,
					url: self.XT_URL + '/xt/workflowAction!queryGroupProcUnitHandlers.mbApp'
				},
				success: function(data) {
					data = JSON.parse(data);
					self.aproveData = data.data;
					var arr = [];
					var M = [];
					var W = [];
					$.each(data.data, function(Q, R) {
						$.each(R.handlers, function(T, S) {
							arr.push(S.handlerName);
							if (S.readonly == false) {
								K = S.result;
								I = S.handlerName;
								M.push('<div class="clear">')
								M.push('<div><div class="main-title">');
								M.push('<div class="approve-title"><img src="/static/images/clock_01.png" alt="小图标" class="approve-title-img"/></div><div class="text-content" ><span class="left_line text_left_line"></span><div id="checkbox"><input type="text" value="3" id="handleResult" style="display: none"><div class="textbox"><p><span>' + S.handlerName + '</span></p><div class="labelBox"><label for="agree"><i><span></span></i><input id="agree" type="radio" class="radioItem" name="opinion" value="1">同意</label><label for="disagree"><i><span class=""></span></i><input id="disagree" type="radio" class="radioItem" name="opinion" value="2">不同意</label><label for="read"><i class="checked"><span></span></i><input id="read" type="radio" class="radioItem " name="opinion" value="3" checked="">已阅</label></div></div>' + '<textarea  required class="default_textbox" id="handleOpinion" name="handleOpinion" class="default_textbox" style="width: 100%; height: 80px; border: 1px solid #e7e7e7;">' + S.opinion + '</textarea></div>')
								M.push('</div></div></div></div>');

								N = S.result;
								$("#currentHandleId").val(S.id);
								$("#currentHandleGroupId").val(S.groupId);
								$("#currentHandleSequence").val(S.sequence);
								$("#currentHandleCooperationModelId").val(S.cooperationModelId);
								$("#currentHandleTaskExecuteModeId").val(S.taskExecuteModeId);
								$("#currentHandleAllowAdd").val(S.allowAdd);
								$("#currentHandleAllowSubtract").val(S.allowSubtract);
								$("#currentHandleAllowTransfer").val(S.allowTransfer);
								$("#currentHandleAllowAbort").val(S.allowAbort);
								$("#currentHandleHelpSection").val(S.helpSection);
								$("#currentHandleChiefId").val(S.chiefId);
								$("#currentApprovalRuleId").val(S.approvalRuleId)
							} else {
								W.push('<div class="clear father' + Q + '" ><div>');
								if (R.handlers.length > 1) {
									if (Q == 0) {
										W.push('<div class="approve-title"><img src="/static/images/clock_01.png" alt="小图标" class="approve-title-img"/></div><div class="text-content" id="text-content"><span class="left_line"></span>')
									} else {
										if (T == 0) {
											W.push('<div class="approve-title"><img src="/static/images/clock_01.png" alt="小图标" class="approve-title-img"/></div><div class="text-content" id="text-content"><span class="left_line"></span>')
										} else {
											W.push('<div class="text-content" id="text-content"><span class="left_line sub_line"></span>');
										}
									}

								} else {
									W.push('<div class="approve-title"><img src="/static/images/clock_01.png" alt="小图标" class="approve-title-img"/></div><div class="text-content" id="text-content"><span class="left_line"></span>')
								}
								if (T != 0) {
									W.push('<div class="text-detail approveShow"><div><p class="handlerName approveShow">')
								} else {
									W.push('<div class="text-detail"><div><p class="handlerName">')
								}
								W.push('<span class="approve-title-name">' + S.handlerName + '</span><span class="approve-title-status">' + S.resultDisplayName + '</span>')
								if (R.handlers.length > 1 && T == 0) {
									W.push('<span onclick="Public.conApprove(' +
										Q + ')" style="float: right;margin-top: -.1rem;" class="arrow_icon arrow_icon_up" id="icon' + Q + '">' + '<i class="fa fa-angle-double-up"></i></span>')
								}
								if (T == 0) {
									W.push('</p><div class="approveShow">');
								} else {
									W.push('</p><div>');
								}
								W.push('<p class="discription">' + S.positionName + '</p><p class="approve-dep"><span>' + S.handleKindName + '</span><span>' + S.handleTime + '</span></p><div  class="zb_line"></div></div></div></div></div></div></div>')
							}
						})
					});
					W = W.concat(M);
					$("#auditPanel").append(W.join(""));
				}

			})

			//材料明细
			$.ajax({
				type: 'post',
				async: false,
				url: self.PACTERA_URL + "/BrcDataService/data/httppoxy",
				data: {
					materialEntryId: bizId,
					access_token: access_token,
					url: self.XT_URL + '/xt/cmMaterialEntryDetailAction!query.mbApp'
				},
				success: function(data) {
					data = JSON.parse(data);
					self.dataGrid = data.data.Rows;
				}
			})
			this.viewParam = this.viewParamService.getViewParam();
		},
		// 保存
		save() {
			var M = {};
			M["flowKind"] = "APPROVAL";
			M["handleResult"] = $("#handleResult").val();
			M["handleOpinion"] = $("#handleOpinion").val();
			M["access_token"] = this.viewParam.access_token;
			M["url"] = this.XT_URL + "/xt/workflowAction!saveBizData.mbApp";
			var L = this.viewParamService.getHandlerdata($("#handlerForm").serialize());
			this.getsaveandSubmit(this.Bdata, this.viewParam, L, M);
			
		},
	
		getsaveandSubmit: function(e, d, a, b) {
			var URL = this.PACTERA_URL;
			// $("#mask-loading_self").css("display", "block");
			if (b.handleResult == 0 || b.handleResult == "undefined") {
				// $("#mask-loading_self").css("display", "none");
				alert("请选择处理方式！");
				return false
			}
			if (b.handleResult == 2) {
				if (b.handleOpinion == "") {
					// $("#mask-loading_self").css("display", "none");
					alert("请填写处理意见!");
					return false
				}
			}
			if (typeof (e.name) == "undefined") { } else {
				var c = e.name
			}
			$.extend(e, d, a, b);
			if (typeof (e.name) == "undefined") { } else {
				e.name = c
			}
			var self = this;
			if (this.JBcode == true) {
				$.ajax({
					url: "" + URL + "/BrcDataService/data/httppoxy",
					type: "POST",
					timeout: 16000,
					data: e,
					dataType: "JSON",
					async: true,
					error: function(f, h, g) {
						// $("#mask-loading_self").css("display", "none");
						if (h == "timeout") {
							alert("加载超时,请重试");
							window.history.back();
							$("#mask-loading_self").css("display", "none")
						}
					},
					success: function(g) {
						// $("#mask-loading_self").css("display", "none");
						self.JBcode = false;
						if (typeof (g.message) == "undefined") {
							if (typeof (g.data) == "undefined") {
								alert("请求异常,请刷新重试");
								self.JBcode = true;
								window.history.back();
								// $("#mask-loading_self").css("display", "none")
							} else {
								if (b.url.substring(b.url.indexOf("!") + 1, b.url.indexOf(".mbApp")) == "saveBizData") {
									self.JBcode = true;
									alert("保存成功！");
									// $("#mask-loading_self").css("display", "none")
								} else {
									window.location.href = "" + URL + "/BrcDataService/brc_h5/home.html";
									// $("#mask-loading_self").css("display", "none")
								}
							}
						} else {
							var f = g.message.split(":")[2];
							if (g.message.split(":")[3]) {
								f = f + ":" + g.message.split(":")[3]
							}
							if (f.indexOf("规则下未找到处理人") != -1) {
								$("#mask-loading_self").css("display", "none");
								f = f + "请转到PC（电脑）端提交。"
							}
							alert(f);
							// $("#mask-loading_self").css("display", "none");
							self.JBcode = true
						}
					}
				})
			}
		},
		// 提交
		getadvance() {
			var M = {};
			M["flowKind"] = "APPROVAL";
			M["handleResult"] = $("#handleResult").val();
			M["handleOpinion"] = $("#handleOpinion").val();
			M["access_token"] = this.viewParam.access_token;
			if (this.viewParam.taskKindId == "replenish") {
				
				// M["url"] = this.XT_URL + "/xt/expenseAccountAction!completeReplenishTask.mbApp";
				M["url"] = 'http://xtm.brc.com.cn:9998' + "/xt/expenseAccountAction!completeReplenishTask.mbApp"
			} else {
				// M["url"] = this.XT_URL + "/xt/workflowAction!advance.mbApp"
				M["url"] = 'http://xtm.brc.com.cn:9998' + "/xt/workflowAction!advance.mbApp"
			}
			var L = this.viewParamService.getHandlerdata($("#handlerForm").serialize());
			this.getsaveandSubmit(this.Bdata, this.viewParam, L, M);
		},
		// 附件
		goFileData(id) {
			this.openPostWindow(this.XT_URL + "/xt/attachmentPreview.do", {id: id, bizCode: '', bizId: '', isReadOnly: true, convertForPhone: true})
		},
		// 打开新窗口 
		openPostWindow(url, param) {
			var name = "form" + new Date().getTime();
			var tempForm = $('<form method="post"></form>');
			tempForm.attr('action', url);
			tempForm.attr('target', name);

			$.each(param, function(p, v) {
				if (!v) return;
				var hideInput = $('<input type="hidden" name="' + p + '"/>');
				hideInput.val(encodeURI(v));
				tempForm.append(hideInput);
			});
			tempForm.appendTo('body');
			tempForm.on('submit', function() {
				window.open('about:blank', name);
			});

			tempForm.trigger('submit');
			tempForm.remove();
			return false;
		}
	},
	mounted() {
		this.getData();

	}
}
</script>
